package com.bwie.system.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bwie.common.domain.RedPacketReceived;
import com.bwie.common.result.Result;
import com.bwie.system.mapper.EsRedPacketReceivedMapper;
import com.bwie.system.mq.domain.EsRedPacketReceived;
import com.bwie.system.service.EsRedPacketReceivedService;
import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
import org.dromara.easyes.core.kernel.EsWrappers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Junchen_N1
 * @Date 2025/6/17 17:19
 * @ClassName EsRedPacketReceivedServiceImpl
 * @Description TODO
 */
@Service
public class EsRedPacketReceivedServiceImpl implements EsRedPacketReceivedService {

    @Autowired
    private EsRedPacketReceivedMapper esRedPacketReceivedMapper;

    /**
     * 清空该索引
     */
    @Override
    public void flushEs() {
        LambdaEsQueryWrapper<EsRedPacketReceived> wrapper = EsWrappers.lambdaQuery(EsRedPacketReceived.class);
        wrapper.matchAllQuery();
        esRedPacketReceivedMapper.delete(wrapper);
    }

    /**
     * 列表查询
     * @param redPacketName
     * @return
     */
    @Override
    public Result<List<EsRedPacketReceived>> selectSnatchMsg(String redPacketName) {
        LambdaEsQueryWrapper<EsRedPacketReceived> wrapper = EsWrappers.lambdaQuery(EsRedPacketReceived.class);
        wrapper.like(EsRedPacketReceived::getRedPacketName,redPacketName);
        List<EsRedPacketReceived> esRedPacketReceivedList = esRedPacketReceivedMapper.selectList(wrapper);
        return Result.success(esRedPacketReceivedList);
    }

    /**
     * es中根据红包id查询红包详情
     * @param redPacketId
     * @return
     */
    @Override
    public Result<List<EsRedPacketReceived>> selectMsgOfRedPacket(Integer redPacketId) {
        LambdaEsQueryWrapper<EsRedPacketReceived> wrapper = EsWrappers.lambdaQuery(EsRedPacketReceived.class);
        wrapper.eq(EsRedPacketReceived::getRedPacketId,redPacketId);
        List<EsRedPacketReceived> esRedPacketReceivedList = esRedPacketReceivedMapper.selectList(wrapper);
        return Result.success(esRedPacketReceivedList);
    }
}
